/**
 * Created by DukeCrushIt on 2015/8/5.
 */
//module game{
    class MoveItem {
        public disObject:egret.DisplayObject;
        private gapX:number;
        private gapY:number;
        public targetX:number;
        public targetY:number;
        public duration:number;
        public past:number;
        private roll:boolean=false;
        public callBackObj:any;
        public callBackFun:Function;
        public isComplete:boolean = false;
        public constructor(){
            //super();
        }
        public init(disObject:egret.DisplayObject,targetX:number,targetY:number,duration:number,cbObj:any=null,cbFun:Function=null,roll:boolean=false){
            this.disObject = disObject;
            this.targetX = targetX;
            this.gapX = targetX - disObject.x;
            this.targetY = targetY;
            this.gapY = targetY - disObject.y;
            this.duration = duration;
            this.past = 0;
            this.callBackObj = cbObj;
            this.callBackFun = cbFun;
            this.roll = roll;// && !PerformanceMonitor.getInstance().inLowModel;
            this.isComplete = false;
        }

        public update(deltaTime:number){
            this.past += deltaTime;
            if( this.past < this.duration){
                var refer:number = deltaTime/this.duration;
                this.disObject.x += this.gapX*refer;
                this.disObject.y += this.gapY*refer;
                if( this.roll){
                    this.disObject.rotation += this.gapX > 0 ? 3 : -3;
                }
            }else{
                this.disObject.x = this.targetX;
                this.disObject.y = this.targetY;
                if( this.callBackObj!= null && this.callBackObj != null)
                    this.callBackFun.call(this.callBackObj);
                MoveMgr.getInstance().delItem(this);
            }
            if( this.disObject.parent == null){
                MoveMgr.getInstance().delItem(this);
            }
        }

        public finish(){
            this.isComplete = true;
            if(this.disObject != null){
                this.disObject.x = this.targetX;
                this.disObject.y = this.targetY;
            }
            if( this.callBackFun != null && this.callBackObj != null){
                this.callBackFun.call(this.callBackObj);
                this.callBackFun = null;
                this.callBackObj = null;
            }
            this.roll = false;
            MoveMgr.getInstance().delItem(this);
        }
    }
//}